package com.crscd.ai.controller;

import com.alibaba.cloud.ai.dashscope.agent.DashScopeAgent;
import com.alibaba.cloud.ai.dashscope.agent.DashScopeAgentOptions;
import com.alibaba.cloud.ai.dashscope.api.DashScopeAgentApi;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created with IntelliJ IDEA.
 *
 * @description:
 * @author: liuziyang
 * @since: 10/11/25 3:53 PM
 * @modifiedBy:
 * @version: 1.0
 */
@RestController
public class MenuCallAgentController {
  // 百炼平台的appid
  @Value("${spring.ai.dashscope.agent.options.app-id}")
  private String appId;

  // 百炼云端智能体调用对象
  private DashScopeAgent agent;

  // 构造方法注入，创建百炼云端智能体对象
  public MenuCallAgentController(DashScopeAgentApi agentApi) {
    this.agent = new DashScopeAgent(agentApi);
  }

  @GetMapping("/eatAgent")
  public String eatAgent(@RequestParam(name = "topic", defaultValue = "今天中午吃什么") String topic) {
    DashScopeAgentOptions options = DashScopeAgentOptions.builder().withAppId(appId).build();

    Prompt prompt = new Prompt(topic, options);

    return agent.call(prompt).getResult().getOutput().getText();
  }
}
